Recent Backupsから日時・ページ数・リンク数を抽出する
https://scrapbox.io/projects/${projectName}/settings/backup を開いて実行する
code:js
(() => {
// scrapbox.io/projects/${projectName}/settings/backup
class BackupRecord {
constructor({ date, time, pageCount, linkCount }) {
this.date = date;
this.time = time;
this.pageCount = pageCount;
this.linkCount = linkCount;
}
toString() {
return this.date, this.time, this.pageCount, this.linkCount.join("\t");
}
}
const openAllBackupRecords = () => {
document.querySelectorAll(".group-label").forEach((elem) => {
const open = elem.querySelector("span.open");
if (open) return;
elem.click();
});
};
const readRecords = () => {
const records = [];
document.querySelectorAll(".backup-item").forEach((backupItem) => {
const label = backupItem.querySelector("label").innerText;
const helpBlock = backupItem.querySelector(".help-block").innerText;
const date, time = label.split(" ");
// bookmarkleterが??に対応していない
const pageCount, linkCount = helpBlock === "" ? "" : helpBlock.match(/\d+/g);
records.push(new BackupRecord({ date, time, pageCount, linkCount }));
});
return records;
};
const print = (body) => {
const bom = new Uint8Array(0xef, 0xbb, 0xbf);
const url = URL.createObjectURL(
new Blob(bom, body, {
type: "text/plain",
})
);
window.open(url);
};
const printRecords = (records) => {
print(records.map((record) => record.toString()).join("\n"));
};
const main = () => {
openAllBackupRecords();
const records = readRecords();
printRecords(records);
};
main();
})();
ブックマークレット